<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Boolean Type</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.1.2 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Data Types"
HREF="datatype.html"><LINK
REL="PREVIOUS"
TITLE="Date/Time Types"
HREF="datatype-datetime.html"><LINK
REL="NEXT"
TITLE="Enumerated Types"
HREF="datatype-enum.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2011-12-01T22:07:59"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.1.2 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="Date/Time Types"
HREF="datatype-datetime.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="datatype.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 8. Data Types</TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="Enumerated Types"
HREF="datatype-enum.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="DATATYPE-BOOLEAN"
>8.6. Boolean Type</A
></H1
><P
>    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> provides the
    standard <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> type <TT
CLASS="TYPE"
>boolean</TT
>;
    see <A
HREF="datatype-boolean.html#DATATYPE-BOOLEAN-TABLE"
>Table 8-19</A
>.
    The <TT
CLASS="TYPE"
>boolean</TT
> type can have several states:
    <SPAN
CLASS="QUOTE"
>"true"</SPAN
>, <SPAN
CLASS="QUOTE"
>"false"</SPAN
>, and a third state,
    <SPAN
CLASS="QUOTE"
>"unknown"</SPAN
>, which is represented by the
    <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> null value.
   </P
><DIV
CLASS="TABLE"
><A
NAME="DATATYPE-BOOLEAN-TABLE"
></A
><P
><B
>Table 8-19. Boolean Data Type</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>Name</TH
><TH
>Storage Size</TH
><TH
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="TYPE"
>boolean</TT
></TD
><TD
>1 byte</TD
><TD
>state of true or false</TD
></TR
></TBODY
></TABLE
></DIV
><P
>    Valid literal values for the <SPAN
CLASS="QUOTE"
>"true"</SPAN
> state are:
    <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><TT
CLASS="LITERAL"
>TRUE</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'t'</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'true'</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'y'</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'yes'</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'on'</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'1'</TT
></TD
></TR
></TBODY
></TABLE
><P
></P
>
    For the <SPAN
CLASS="QUOTE"
>"false"</SPAN
> state, the following values can be
    used:
    <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><TT
CLASS="LITERAL"
>FALSE</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'f'</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'false'</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'n'</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'no'</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'off'</TT
></TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>'0'</TT
></TD
></TR
></TBODY
></TABLE
><P
></P
>
    Leading or trailing whitespace is ignored, and case does not matter.
    The key words
    <TT
CLASS="LITERAL"
>TRUE</TT
> and <TT
CLASS="LITERAL"
>FALSE</TT
> are the preferred
    (<ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
>-compliant) usage.
   </P
><P
>    <A
HREF="datatype-boolean.html#DATATYPE-BOOLEAN-EXAMPLE"
>Example 8-2</A
> shows that
    <TT
CLASS="TYPE"
>boolean</TT
> values are output using the letters
    <TT
CLASS="LITERAL"
>t</TT
> and <TT
CLASS="LITERAL"
>f</TT
>.
   </P
><DIV
CLASS="EXAMPLE"
><A
NAME="DATATYPE-BOOLEAN-EXAMPLE"
></A
><P
><B
>Example 8-2. Using the <TT
CLASS="TYPE"
>boolean</TT
> Type</B
></P
><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE test1 (a boolean, b text);
INSERT INTO test1 VALUES (TRUE, 'sic est');
INSERT INTO test1 VALUES (FALSE, 'non est');
SELECT * FROM test1;
 a |    b
---+---------
 t | sic est
 f | non est

SELECT * FROM test1 WHERE a;
 a |    b
---+---------
 t | sic est</PRE
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="datatype-datetime.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="datatype-enum.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Date/Time Types</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="datatype.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Enumerated Types</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>